package com.abocode.happybean.copy;

/**
 * @author guanxf
 */
public class StringUtils {
    public static String capitalize(String str) {
        return changeFirstCharacterCase(str, true);
    }

    public static boolean hasLength(String str) {
        return str != null && str.length()!= 0;
    }

    private static String changeFirstCharacterCase(String str, boolean capitalize) {
        if (!hasLength(str)) {
            return str;
        } else {
            char baseChar = str.charAt(0);
            char updatedChar;
            if (capitalize) {
                updatedChar = Character.toUpperCase(baseChar);
            } else {
                updatedChar = Character.toLowerCase(baseChar);
            }

            if (baseChar == updatedChar) {
                return str;
            } else {
                char[] chars = str.toCharArray();
                chars[0] = updatedChar;
                return new String(chars, 0, chars.length);
            }
        }
    }

    public static boolean isEmpty(String str) {
        if (str==null|| str.length()==0){
            return true;
        }
        return false;
    }

    public static boolean isJavaClass(Class<?> clz) {
        return clz != null && clz.getClassLoader() == null;
    }
}
